package com.chuang.bootplus.controller.admin;


import com.alibaba.excel.EasyExcel;
import com.chuang.bootplus.entity.document.Document;
import com.chuang.bootplus.service.DocumentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"Download"})
@RestController
@RequestMapping("/download")
public class DownLoaderController {


    static String filePath="C:\\Users\\jokehe\\Desktop\\wtd\\document\\";

    @Autowired
    DocumentService documentService;

    @Transactional
    @PostMapping("/download")
    public String downloadFile()  {
        String fileName = filePath+ "document"+ ".xlsx";
        // 这里 需要指定写用哪个class去读，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, Document.class).sheet("模板").doWrite(documentService.list());
        return "ok";
    }







}
